package com.jeff.cloud.consumermovie.feign;

import com.jeff.cloud.consumermovie.bean.User;
import com.jeff.cloud.consumermovie.config.FeignLogConfiguration;
import org.omg.CORBA.Request;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.cloud.netflix.feign.FeignLoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 本例中使用了eureka,Ribbon会把"microservice-provider-user"解析成Eureka服务注册表中的服务。
 * 如果不想使用eureka，可以yml使用service.ribbon.listOfServers属性配置服务器列表.
 * 结果看来，不但实现了声明式的RestApi调用，同时还实现了客户端侧的负载均衡。
 * @author: jeff
 * @date: 2021/8/9 14:36
 */
@FeignClient(name="microservice-provider-user",configuration = FeignLogConfiguration.class)
public interface UserFeignClient {
    @RequestMapping(value="/{id}",method = RequestMethod.GET)
    public User findById(@PathVariable("id") Long id);

    //feign多参数GET请求构建示例 -----------------
    //示例一：该示例比较直观，URL有几个参数，Feign接口就有几个参数，@RequestParam指定请求的参数是什么
    @RequestMapping(value="/get",method = RequestMethod.GET)
    public User get1(@RequestParam("id") Long id,@RequestParam("username") String username);

    //示例二：多参数的URL用Map来构建，简化Feign接口的编写
    @RequestMapping(value = "/get",method = RequestMethod.GET)
    public User get2(@RequestParam Map<String,Object> map);

    //feign多参数POST请求构建示例 -----------------
    @RequestMapping(value = "/post",method = RequestMethod.POST)
    public User post(@RequestBody User user);
}
